import os
from glob import  glob
from tqdm import tqdm
import json
import shutil

image_dir = "/data/lzy/coco_bak/all/"
image_list = glob(os.path.join(image_dir, "*"))
json_dir = "/data/lzy/coco_bak/all.json"
with open(json_dir) as f:
    annos = json.load(f)

anno_images = annos['images']
image_name_list = []
for anno in anno_images:
    image_name_list.append(anno['file_name'])

for image_name in image_list:
    if(os.path.basename(image_name) not in image_name_list):
        os.remove(image_name)